#ifndef _COMPAT_THREAD_H_
#define _COMPAT_THREAD_H_

#include <compat/define.h>
#include <compat/error.h>

#ifdef	__cplusplus
extern "C" 
{
#endif



int os_mutex_init(os_mutex_t* mutex);
int os_mutex_init_recursive(os_mutex_t* mutex);
void os_mutex_destroy(os_mutex_t* mutex);
void os_mutex_lock(os_mutex_t* mutex);
int os_mutex_trylock(os_mutex_t* mutex);
void os_mutex_unlock(os_mutex_t* mutex);

int os_rwlock_init(os_rwlock_t* rwlock);
void os_rwlock_destroy(os_rwlock_t* rwlock);
void os_rwlock_rdlock(os_rwlock_t* rwlock);
int os_rwlock_tryrdlock(os_rwlock_t* rwlock);
void os_rwlock_rdunlock(os_rwlock_t* rwlock);
void os_rwlock_wrlock(os_rwlock_t* rwlock);
int os_rwlock_trywrlock(os_rwlock_t* rwlock);
void os_rwlock_wrunlock(os_rwlock_t* rwlock);

int os_sem_init(os_sem_t* sem, unsigned int value);
void os_sem_destroy(os_sem_t* sem);
void os_sem_post(os_sem_t* sem);
void os_sem_wait(os_sem_t* sem);
int os_sem_trywait(os_sem_t* sem);

int os_cond_init(os_cond_t* cond);
void os_cond_destroy(os_cond_t* cond);
void os_cond_signal(os_cond_t* cond);
void os_cond_broadcast(os_cond_t* cond);
void os_cond_wait(os_cond_t* cond, os_mutex_t* mutex);
int  os_cond_timedwait(os_cond_t* cond, os_mutex_t* mutex, uint64_t timeout);

void os_once(os_once_t* guard, void(*callback)(void));

int os_key_create(os_key_t* key);
void os_key_delete(os_key_t* key);
void* os_key_get(os_key_t* key);
void os_key_set(os_key_t* key, void* value);

typedef void(*os_thread_cb)(void* arg);

int os_thread_create(os_thread_t* tid, os_thread_cb entry, void* arg);
os_thread_t os_thread_self(void);
os_thread_id os_getthread_id(os_thread_t *thander);
int os_thread_join(os_thread_t *tid);
int os_thread_equal(const os_thread_t* t1, const os_thread_t* t2);


#ifdef	__cplusplus
}
#endif

#endif
